using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Globalization;

namespace ValidationFramework
{
    /// <summary>
    /// Validates if the binding value is between minimum value or the maximum value
    /// </summary>
    public class RangeValidationRule: ValidationRuleBase
    {
        #region Private Fields

        private IComparable _minValue;
        private IComparable _maxValue;

        #endregion

        /// <summary>
        /// Validates if the value is between the minimum value and the maximum value
        /// </summary>
        /// <param name="value"></param>
        /// <param name="cultureInfo"></param>
        /// <returns></returns>
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            ValidationResult result = new ValidationResult(true, null);
            IComparable comparableValue = value as IComparable;

            if (comparableValue.CompareTo(_minValue) >= 0 && comparableValue.CompareTo(_maxValue) <= 0)
            {
                result = new ValidationResult(false, ErrorMessage);
            }

            return result;
        }

        #region Public Properties

        /// <summary>
        /// Gets or sets the maximum value
        /// </summary>
        public IComparable MaxValue
        {
            get { return _maxValue; }
            set { _maxValue = value; }
        }

        /// <summary>
        /// Gets or sets the minimum value
        /// </summary>
        public IComparable MinValue
        {
            get { return _minValue; }
            set { _minValue = value; }
        }

        #endregion
    }
}
